package com.stox.client.ui.javafx.chartingy.widget.toolbar;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToolBar;

import com.stox.client.ui.javafx.chartingy.view.ChartingView;
import com.stox.client.ui.javafx.chartingy.widget.IndicatorChooserPopupControl;
import com.stox.client.ui.javafx.core.util.CSS;
import com.stox.client.ui.javafx.core.util.UI;
import com.stox.client.ui.javafx.workbench.stage.StoxStage;
import com.stox.shared.core.i18n.MessageSource;

public class ChartingToolBar extends ToolBar {

	private final Button indicatorButton = UI
			.control(new Button(MessageSource.get("Indicator")), MessageSource.get("Add.an.Indicator"), true, false, CSS.green);
	private final Button screenButton = UI.control(new Button(MessageSource.get("Screen")), MessageSource.get("Add.a.Screen"), true, false, CSS.green);
	private final Button patternButton = UI.control(new Button(MessageSource.get("Pattern")), MessageSource.get("Add.a.Pattern"), true, false, CSS.green);
	private final Button analysisButton = UI.control(new Button(MessageSource.get("Analysis")), MessageSource.get("Add.a.Pattern"), true, false, CSS.green);
	private final Button strategyButton = UI.control(new Button(MessageSource.get("Strategy")), MessageSource.get("Add.a.Pattern"), true, false, CSS.green);
	private final ToggleButton autoUpdateToggleButton = UI.control(new ToggleButton(MessageSource.get("Auto")), MessageSource.get("Auto.Update.Data"), true, false, "", CSS.textButton);
	
	public ChartingToolBar(final ChartingView chartingView) {
		setMaxWidth(Double.MAX_VALUE);
		UI.style(this, CSS.chartingToolBar);
		indicatorButton.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(final ActionEvent event) {
				final IndicatorChooserPopupControl chooser = new IndicatorChooserPopupControl(chartingView);
				chooser.show(StoxStage.INSTANCE);
			}
		});
		autoUpdateToggleButton.selectedProperty().bindBidirectional(chartingView.autoUpdateProperty());
		getItems().addAll(new BasicTools(chartingView), indicatorButton, screenButton, patternButton, analysisButton, strategyButton,
				new ZoomTools(chartingView),autoUpdateToggleButton, UI.spacer());
	}
}
